package edu.washington.cs.workflow.analysis.guistructure.uievents;

import edu.washington.cs.workflow.analysis.guistructure.uievents.UIEvent.WINDOW;
import edu.washington.cs.workflow.util.Utils;

public class UIEventThread extends Thread {
	
	private UIEvent event = null;
	
	private UIEventOutcome outcome = null;
	
	public void setUIEvent(UIEvent e) {
		Utils.checkNotNull(e);
		this.event = e;
	}
	
	public UIEventOutcome getOutcome() {
		return this.outcome;
	}
	
	public boolean isFinished() {
		return this.outcome != null;
	}
	
	@Override
	public final void run() {
		if(event.canFireEvent()) {
		    WINDOW w = event.probeWindowInfo();
		    this.outcome = event.fireEvent();
		}
	}
	
	public static void main(String[] args) {
		UIEventThread t = new UIEventThread();
		t.start();
		try {
//			t.join(1000);
			t.join(2000, 20);
			t.stop(); //interrupt it
			System.out.println("stop ");
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("outside ");
	}
}
